<!-- 融资企业待办 - 变更已办 -->
<template>
  <div>
    <Review ref="review" @ok="search"></Review>
    <ZgNewPage
      ref="page"
      :title="pageTitle"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="90"
      :scrollX="1500"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          align="center"
          :title="h.label"
        >
          <template slot-scope="record">
            <template v-if="h.code === 'B'">
              <span style="color: #1890ff">{{ record[h.code] }}</span>
            </template>
            <template v-else-if="h.code === 'H'">
              <span>{{ H[record[h.code]] }}</span>
            </template>
            <template v-else>{{ record[h.code] }}</template>
          </template>
        </a-table-column>
      </template>
      <template slot="thMode" slot-scope="scope">
        <a-row :gutter="10">
          <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
            <a-card class="mb10">
              <div class="wfull h100 scroll">
                {{ t }}
              </div>
            </a-card>
          </a-col>
        </a-row>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
import Review from './Review'
const statusList = [
  { value: '1', label: '审核通过' },
  { value: '2', label: '待审核' },
  { value: '3', label: '驳回' }
]
export default {
  components: {
    Review
  },
  data() {
    return {
      pageTitle: '等级管理',
      uniqueName: 'test',
      H: {
        1: '审核通过',
        2: '待审核',
        3: '驳回'
      },
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true,
        showAttachBtn: true,
        showDataCheck: true,
        showPageTitle: false
      },
      conditions: [
        {
          code: 'code',
          compType: '单行文本',
          label: '企业代码',
          defaultVal: '',
          extra: { placeholder: '请输入企业代码' }
        },
        {
          code: 'name',
          compType: '单行文本',
          label: '企业名称',
          defaultVal: '',
          extra: { placeholder: '请输入企业名称' }
        },
        {
          code: 'name',
          compType: '单行文本',
          label: '信用代码',
          defaultVal: '',
          extra: { placeholder: '请输入信用代码' }
        },
        {
          code: 'date',
          compType: '日期区间',
          label: '申请日期',
          defaultVal: '',
          extra: { placeholder: '请选择申请日期' }
        },
        {
          code: 'code',
          compType: '单行文本',
          label: '焦煤编号',
          defaultVal: '',
          extra: { placeholder: '请输入焦煤编号' }
        },
        {
          code: 'code',
          compType: '单行文本',
          label: '物流编号',
          defaultVal: '',
          extra: { placeholder: '请输入物流编号' }
        },
        {
          code: 'status',
          compType: '下拉选择',
          label: '状态',
          defaultVal: '',
          extra: { 下拉选项: statusList, placeholder: '请选择状态' }
        }
      ],
      headers: [
        { code: 'A', label: '企业代码', isShow: true, sort: 0 },
        { code: 'B', label: '企业名称', isShow: true, sort: 0 },
        { code: 'C', label: '信用代码', isShow: true, sort: 0 },
        { code: 'D', label: '企业性质', isShow: true, sort: 0 },
        { code: 'E', label: '客户类型', isShow: true, sort: 0 },
        { code: 'F', label: '焦煤编号', isShow: true, sort: 0 },
        { code: 'G', label: '物流编号', isShow: true, sort: 0 },
        { code: 'H', label: '审核状态', isShow: true, sort: 0 },
        { code: 'I', label: '注册时间', isShow: true, sort: 0 },
        { code: 'J', label: '申请时间', isShow: true, sort: 0 }
      ],
      dataBtns: [
        {
          key: 1,
          name: '审核',
          type: 'link',
          isShow: () => {
            return true
          }
        }
      ]
    }
  },
  methods: {
    search() {
      this.$refs.page.search()
    },
    onSearch(param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        {
          key: '1',
          id: '1',
          A: '2021120',
          B: '秦皇岛楚彤商贸有限公司',
          C: '91141181699136277J',
          D: '国有',
          E: '焦煤用户',
          F: '36800321',
          G: '2c90829c60df699301610c6c35f9bd',
          H: '2',
          I: '',
          J: ''
        },
        {
          key: '2',
          id: '2',
          A: '2021120',
          B: '山西智恒物贸有限公司',
          C: '91141181699136277J',
          D: '民营',
          E: '物流用户',
          F: '36800321',
          G: '2c90829c60df699301610c6c35f9bd',
          H: '2',
          I: '',
          J: ''
        }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onFilter(f, param) {},
    toAdmin(param) {
      if (param.key === 1) {
        this.$refs.review.open()
      }
    },
    mergeHeader(newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders
        .filter((t) => {
          return t.isShow
        })
        .sort((a, b) => {
          return a.sort - b.sort
        })
    }
  }
}
</script>

<style lang="scss" scoped></style>
